%%%-------------------------------------------------------------------
%%% @author zhang
%%% @copyright (C) 2018, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 21. 十一月 2018 18:54
%%%-------------------------------------------------------------------
-module(emqx_tc_mq).
-author("zhang").
-include_lib("amqp_client/include/amqp_client.hrl").
%% API
-export([send/1]).

send(Message) ->
    %% Start a network connection                                      
    {ok, Connection} = amqp_connection:start(#amqp_params_network{username = <<"zzz">>, password = <<"123">>, port = 5672}),
    %% Open a channel on the connection                                
    {ok, Channel} = amqp_connection:open_channel(Connection),

    %% Publish a message                                               
    Payload = Message,
    Publish = #'basic.publish'{exchange = <<"zzztest">>, routing_key = <<"zzzkey">>},
    amqp_channel:cast(Channel, Publish, #amqp_msg{payload = Payload}),

    %% Close the channel
    amqp_channel:close(Channel),
    %% Close the connection                                            
    amqp_connection:close(Connection),
    ok.
